package edu.gyc.hiwxm.controller;


import edu.gyc.hiwxm.exception.BookingException;
import edu.gyc.hiwxm.model.Booking;
import edu.gyc.hiwxm.model.Girl;
import edu.gyc.hiwxm.model.Vip;
import edu.gyc.hiwxm.myenum.BookingStatusEnum;
import edu.gyc.hiwxm.service.BookingService;
import edu.gyc.hiwxm.service.GirlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ls
 * @since 2020-01-01
 */
@Controller
@RequestMapping("/booking")
public class BookingController {
@Autowired
private BookingService bookingService;

@Autowired
private GirlService girlService;
    @RequestMapping("/list")
    public String list(Model model) {
        model.addAttribute("bookings", bookingService.getAllGirlBookingReport());
        return "booking/index";
    }

    @RequestMapping("/kiss")
    public String kissGirl(Integer girlid,Model model,HttpSession session) {
        session.setAttribute("girlId",girlid);

        return "booking/prebooking";
    }

    @RequestMapping("/dokiss")
    public String dokissGirl(String  bookingDate,Model model,HttpSession session) {
     Integer id= (Integer) session.getAttribute("girlId");
        List<Booking> bookings= bookingService.getGirlBookingReport(bookingDate,id);
        model.addAttribute("bookings",bookings);
        return "booking/kiss";
    }
    //抢单，已预约的钱多的可强行预约
    @RequestMapping("/rob")
    public String rob(Integer loveid,Model model) {
       // List<Booking> bookings= bookingService.getGirlBookingReport(girlid);
        Booking booking = bookingService.getById(loveid);
        Girl girl = girlService.getById(booking.getGirlId());
        model.addAttribute("girl",girl);
        model.addAttribute("booking", booking);
        return "booking/rob";
    }
    @RequestMapping("/robing")
    public String bookingRobing(Integer id,Integer bookingPrice, Model model, HttpSession session) {
        Booking booking = bookingService.getById(id);
        Vip vip = (Vip) session.getAttribute("user");
        if (vip == null) {
            throw new BookingException("请先登录");
        }
      String msg=  bookingService.booking(vip.getId(), booking.getGirlId(), id, bookingPrice);
        model.addAttribute("msg",msg);
        return "success";
    }
    @RequestMapping("/love")
    public String bookingLoveGirl(Integer loveid, Model model, HttpSession session) {
        Booking booking = bookingService.getById(loveid);
        Vip vip = (Vip) session.getAttribute("user");
        if (vip == null) {
            throw new BookingException("请先登录");
        }
      String msg=  bookingService.booking(vip.getId(), booking.getGirlId(), loveid);
        model.addAttribute("msg",msg);
        return "success";
    }
}

